/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sistemadeleiloes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

/**
 *
 * @author Pedro
 */
public class LanceDAO {

    /*public boolean inserirLance(double valor, Date horaLance, int idUsuario, int idLeilao) throws SQLException {
     Connection conn = Database.getConnection();
     String sql = "INSERT INTO lances VALUES (?,?,?)";
        
     try{
     PreparedStatement pstm = conn.prepareStatement(sql);
     pstm.setDouble(1, valor);
     pstm.setDate(2, (java.sql.Date) horaLance);
     pstm.setInt(3, idUsuario);
     pstm.setInt(4, idLeilao);
     return (pstm.executeUpdate() != 0);

     } catch(SQLException e){
     System.out.println("Erro ao inserir: " + e);
     }
        
     return false;
     }*/
    
    public boolean arrematar(int idLeilao, int idUsuario, Date horaLance) throws SQLException {
        Connection conn = Database.getConnection();
        String sql = "EXEC sp_updLeilao ?,?,?";

        try {
            PreparedStatement pstm = conn.prepareStatement(sql);
            pstm.setInt(1, idLeilao);
            pstm.setInt(2, idUsuario);
            pstm.setDate(3, (java.sql.Date) horaLance);


            return (pstm.executeUpdate(sql) != 0);

            /**
             * **************** IMPLEMENTAR ENVIO DE EMAIL APÓS ARREMATE **************
             */
        } catch (SQLException e) {
            System.out.println("Erro ao atualizar: " + e);
        }

        return false;
    }
}
